 //var serverUrl = '/beautyos/index.php/';
/**
 * 文件管理器的Toolbar 放工具栏
 * fileToolbar的各种工具widgets
 * 
 */
var fileToolbar = new Ext.Toolbar({
	//renderTo:win,
	items:[{
		text:'后退',
		iconCls:'icon-grid'
 	},{
    	
    	text:'前进',
    	iconCls:'icon-grid'
    },{
    	text:'向上',
    	iconCls:'icon-grid'
    },{
    	text:'文件夹',
    	iconCls:'icon-grid'
    },{
    	text:'文件',
    	iconCls:'icon-grid'
    },{
    	text:'搜索',
    	iconCls:'icon-grid'
    },{
    	text:'上传',
    	iconCls:'icon-grid'
    },{
    	text:'下载',
    	iconCls:'icon-grid'
    },{
    	text:'复制',
    	iconCls:'icon-grid'
    },{
    	text:'粘贴',
    	iconCls:'icon-grid'
    }]
})

/**
 * 文件管理器的地址栏
 * 
 */
var address = new Ext.FormPanel({
		labelWidth: 75, // 默认标签宽度板
	    baseCls: 'x-plain',//不设置该值，表单将保持原样，设置后表单与窗体完全融合
	    border:true,
	    defaultType: 'textfield',//默认字段类型
		items: [{
	    	fieldLabel: '地址栏',
	        name: 'file_address'
	    }]
});
var fileAddress = new Ext.Panel({
	region:'north',
 	//title:'地址栏',
 	//height:20
 	//cls:'empty',
 	//html:'<input type="text"/>'
	//split:true,
 	//layout:'form',
 	height:22,
 	//collapsible: true, 
    items:[{title:'地址栏'}] 
	//items:[address] 
});

/**
 * 文件管理器的西面 放文件夹树和搜索
 * 
 */
/*
 * 
 * 
var fileTree = new Ext.Panel({
	title: '文件夹'
	//html: '&lt;empty panel&gt;'
	
 	//cls:'empty'
});
var searchForm = new Ext.Panel({
	title: '搜索',
	html: '&lt;empty panel&gt;',
	collapsible: true, 
 	cls:'empty'
});*/

var rightClick = new Ext.menu.Menu({
        id :'rightClickCont',
        items : [{
            id:'rMenu1',
            text : '菜单1',
            //增加菜单点击事件
            handler:function (){
                 alert('我被点击了！');
            }
        }, {
            id:'rMenu2',
            text : '菜单2'
        }, {
            id:'rMenu3',
            text : '菜单3'
        }]
});


var fileAccordion = new Ext.Panel({
	region:'west',
	margins:'5 0 5 5',
 	split:true,
	width: 210,
 	layout:'accordion',
 	collapsible: true, 
   // items: [fileTree,searchForm]
	items:[
  		new Ext.tree.TreePanel({
        	id:'file-tree',
            title: '文件夹',
            loader: new Ext.tree.TreeLoader({
            	dataUrl:serverUrl+'fileManager/getDirTree'
            }),
            rootVisible:false,
            lines:false,
            autoScroll:true,
            tools:[{
            	id:'refresh',
                on:{
               		click: function(){
                    	var tree = Ext.getCmp('file-tree');
                        tree.body.mask('Loading', 'x-mask-loading');
                        tree.root.reload();
                        tree.root.collapse(true, false);
                        setTimeout(function(){ // mimic a server call
                        	tree.body.unmask();
                            tree.root.expand(true, true);
                       }, 1000);
                	}
                	
             	}
             }],
             root: new Ext.tree.AsyncTreeNode({
             		text:'文件夹',
             		id:'0',
             		draggable:false 
             }),
             contextmenu:function(node,event){
                		event.preventDefault();
                		rightClick.showAt(event.getXY());
             }	
            
             }),{
           		 title: '搜索',
           	 	 html:'<p>Something useful would be in here.</p>',
           		 autoScroll:true
			}
	]
});

var tab = new Ext.TabPanel({
                        activeTab:0,
						 region: 'center', //border布局，将页面分成东，南，西，北，中五部分，这里表示TabPanel放在中间
              			  margins: '3 3 3 0',
                        items: [{
                            title: 'Tab Text 1',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 2',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 3',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 4',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        }]
                    })

/**
 * 文件管理器类
 * 
 * @class MyDesktop.fileManager
 * @extends Ext.app.Module
 */
MyDesktop.fileManager = Ext.extend(Ext.app.Module, {
	id:'file-manager',
	init : function(){
		this.launcher = {
            text: '文件管理器',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
	},
	
	
                    
	createWindow : function() {
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow('file-manager');
		if(!win) {
			win = desktop.createWindow({
				id: 'file-manager',
                title:'文件管理器',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
                layout: 'border',
                tbar:[
                //工具栏
                	new Ext.Toolbar({
	items:[{
		text:'后退',
		iconCls:'icon-grid'
 	},{
    	
    	text:'前进',
    	iconCls:'icon-grid'
    },{
    	text:'向上',
    	iconCls:'icon-grid'
    },{
    	text:'文件夹',
    	iconCls:'icon-grid'
    },{
    	text:'文件',
    	iconCls:'icon-grid'
    },{
    	text:'搜索',
    	iconCls:'icon-grid'
    },{
    	text:'上传',
    	iconCls:'icon-grid'
    },{
    	text:'下载',
    	iconCls:'icon-grid'
    },{
    	text:'复制',
    	iconCls:'icon-grid'
    },{
    	text:'粘贴',
    	iconCls:'icon-grid'
    }]
})
                ],
               // items:[fileAccordion,tab]
                items:[
                	new Ext.Panel({
	region:'west',
	margins:'5 0 5 5',
 	split:true,
	width: 210,
 	layout:'accordion',
 	collapsible: true, 
   // items: [fileTree,searchForm]
	items:[
		//文件夹和搜索
  		new Ext.tree.TreePanel({
        	id:'file-tree',
            title: '文件夹',
            loader: new Ext.tree.TreeLoader({
            	dataUrl:serverUrl+'fileManager/getDirTree'
            }),
            rootVisible:true,
            lines:false,
            autoScroll:true,
            listeners:[{
            	'render': function(tp){
            		 tp.getSelectionModel().on('selectionchange', function(tree, node){
                        var el = Ext.getCmp('folder').body;
	                    alert(el)
                    })
            	}

            }],
            tools:[{
            	id:'refresh',
                on:{
               		click: function(node,event){
               			//alert(node.id)
                    	/*var tree = Ext.getCmp('file-tree');
                        tree.body.mask('Loading', 'x-mask-loading');
                        tree.root.reload();
                        tree.root.collapse(true, false);
                        setTimeout(function(){ // mimic a server call
                        	tree.body.unmask();
                            tree.root.expand(true, true);
                       	}, 1000);*/
                		}
             		}
             	}],
            root: new Ext.tree.AsyncTreeNode({
             	text:'我的电脑',
             	id:'0',
             	draggable:false,
             	expanded:true 
             })
             }),{
           	 title: '搜索',
           	 html:'<p>Something useful would be in here.</p>',
           	 autoScroll:true
             }]
		}),
            //显示文件的详细面板    
            new Ext.grid.GridPanel({
            	id:'folder',
                region:'center',     
            	border:false,
                        ds: new Ext.data.Store({
                        	url:serverUrl+'fileManager/getFileAndFolder',
                        	autoLoad:true, 
                            reader: new Ext.data.ArrayReader({}, [
                               {name: 'company'},
                               {name: 'price', type: 'float'},
                               {name: 'change', type: 'float'},
                               {name: 'pctChange', type: 'float'}
                            ])
                            //data: Ext.grid.dummyData
                        }),
                        cm: new Ext.grid.ColumnModel([
                            new Ext.grid.RowNumberer(),
                            {header: "名称", width: 120, sortable: true, dataIndex: 'company'},
                            {header: "大小", width: 70, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
                            {header: "类型", width: 70, sortable: true, dataIndex: 'change'},
                            {header: "修改时间", width: 70, sortable: true, dataIndex: 'pctChange'}
                        ]),

                        viewConfig: {
                            forceFit:true
                        },
                        //autoExpandColumn:'company',

                        tbar:[{
                            text:'Add Something',
                            tooltip:'Add a new row',
                            iconCls:'add'
                        }, '-', {
                            text:'Options',
                            tooltip:'Blah blah blah blaht',
                            iconCls:'option'
                        },'-',{
                            text:'Remove Something',
                            tooltip:'Remove the selected item',
                            iconCls:'remove'
                        }]
                    })
                ]
                
			});
		}
		
		win.show();
	}
});

// Array data for the grid
Ext.grid.dummyData = [
    ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
    ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
    ['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
    ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
    ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am'],
    ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am'],
    ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am'],
    ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am'],
    ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am'],
    ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am'],
    ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
    ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am'],
    ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am'],
    ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am'],
    ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am'],
    ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am'],
    ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am'],
    ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am'],
    ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am'],
    ['Walt Disney Company (The) (Holding Company)',29.89,0.24,0.81,'9/1 12:00am']
];